﻿package tooltip_pkg
{
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.events.MouseEvent;
	
	public class Tooltip {
	
	private var theTip:MovieClip;
	private var tFormat:TextFormat;
	private var _root: DisplayObjectContainer;
	private var TF: TextField;
	
	function Tooltip(hex:Number, hex2:Number, root: DisplayObjectContainer) {
		_root = root;
		this.theTip = new MovieClip();
		//_root.addChild(theTip);
		
		TF = new TextField();
		TF.x = 3;
		TF.y = 1;
		TF.width = 95;
		TF.height = 20;
		TF.text = "theText";
		TF.selectable = false;
		theTip.addChild(TF);
		
		theTip.graphics.beginFill(hex);
		theTip.graphics.lineStyle(1, hex2, 100);
		theTip.graphics.moveTo(0, 0);
		theTip.graphics.lineTo(100, 0);
		theTip.graphics.lineTo(100, 20);
		theTip.graphics.lineTo(20, 20);
		theTip.graphics.lineTo(15, 30);
		theTip.graphics.lineTo(10, 20);
		theTip.graphics.lineTo(0, 20);
		theTip.graphics.lineTo(0, 0);
		theTip.graphics.endFill();
		
		tFormat = new TextFormat();
		tFormat.font = "Arial";
		tFormat.size = 11;
		tFormat.align = "center";
		TF.setTextFormat(tFormat);
		
		theTip.visible = false;
	}
	
	public function get Visible(): Boolean
	{
		return theTip.visible;
	}
	
	public function showTip(theText:String, X: int, Y: int):void {
		TF.text = theText;
		
		theTip.width = 95;
		if (TF.textWidth > 85)
		  theTip.width = TF.textWidth + 10;
		  
		theTip.x = X - 15;
		theTip.y = Y - 35;
		theTip.visible = true;
		_root.addChild(theTip);
	}
	
	public function removeTip():void {
		this.theTip.visible = false;
		_root.removeChild(theTip);
	}

}
}